
function TwitterApi(requestUrl, screen_name){
	this.requestUrl = requestUrl;
	this.screen_name = screen_name;
	this.errorCallback = null;
}

TwitterApi.prototype = {
	_get : function(url, data, callback){
		$.ajax({
			dataType:'jsonp',
			data : data,
			url : url,
			success : callback,
			error : this.errorCallback
		});
	},
	setErrorCallback : function(callback){
		this.errorCallback = callback;
	},
	resetErrorCallback : function(){
		this.errorCallback = null;
	},
	_requestProxy : function(action ,data, method, callback){
		data['screen_name'] = this.screen_name;
		data['method'] = method;
		data['action'] = action;
		$.ajax({
			dataType:'json',
			type : 'POST',
			data : data,
			url : this.requestUrl,
			success : callback,
			error : this.errorCallback
		});
	},
	debug : function(data, callback){
		var action = "test";
		this._requestProxy(action, data, 'GET', callback);
	},
	/* Search */
	search : function(data, callback){
		var url = "http://search.twitter.com/search.json?callback=?";
		this._get(url, data, callback);
	},
	/* Timelines */
	getPublicTimeline : function(data, callback){
		var url = "http://api.twitter.com/1/statuses/public_timeline.json?callback=?";
		this._get(url, data, callback);
	},
	getUserTimeline : function(data, callback){
		var url = "http://api.twitter.com/1/statuses/user_timeline.json?callback=?";
		this._get(url, data, callback);
	},
	getHomeTimeline : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/home_timeline.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	getHomeTimeline : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/home_timeline.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	getMentions : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/mentions.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	getRetweetsOfMe : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/retweets_of_me.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	getRetweetedToMe : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/retweeted_to_me.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	getRetweetedByMe : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/retweeted_by_me.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	/* Tweet */
	updateStatuses : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/update.json";
		this._requestProxy(action, data, 'POST', callback);
	},
	destroyStatuses : function(statusId, callback){
		var action = "http://api.twitter.com/1/statuses/destroy/" + statusId + ".json";
		this._requestProxy(action, {}, 'POST', callback);
	},
	retweetStatuses : function(statusId, callback){
		var action = "http://api.twitter.com/1/statuses/retweet/" + statusId + ".json";
		this._requestProxy(action, {}, 'POST', callback);
	},
	oembedStatuses : function(data, callback){
		var action = "http://api.twitter.com/1/statuses/oembed.json";
		this._requestProxy(action, data, 'POST', callback);
	},
	updateStatusesWithMedia : function(data, callback){
		var action = "https://upload.twitter.com/1/statuses/update_with_media.json";
		this._requestProxy(action, data, 'POST', callback);
	},
	showStatuses : function(id, data, callback){
		var url = "http://api.twitter.com/1/statuses/show/" + id +".json";
		this._requestProxy(url, data,'GET', callback);
	},
	getRetweetStatuses : function(id, data, callback){
		var action = "http://api.twitter.com/1/statuses/retweets/"+ id +".json";
		this._requestProxy(action, data, 'GET', callback);
	},
	/* Friends & Followers */
	createFriendship : function(data, callback){
		var action = "http://api.twitter.com/1/friendships/create.json";
		this._requestProxy(action, data, 'POST', callback);
	},
	destroyFriendship : function(data, callback){
		var action = "http://api.twitter.com/1/friendships/destroy.json";
		this._requestProxy(action, data, 'POST', callback);
	},
	/* Favorites */
	/* 
	 * お気に入り一覧取得
	 * @param statusId TwitterのつぶやきID
	 */
	getFavorites : function(data, callback){
		var action = "http://api.twitter.com/1/favorites.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	/* 
	 * お気に入り作成
	 * @param statusId TwitterのつぶやきID
	 */
	createFavorites : function(statusId, callback){
		var action = "http://api.twitter.com/1/favorites/create/" + statusId + '.json';
		this._requestProxy(action, {}, 'POST', callback);
	},
	/* 
	 * お気に入り削除
	 * @param statusId TwitterのつぶやきID
	 */
	destroyFavorites : function(statusId, callback){
		var action = "http://api.twitter.com/1/favorites/destroy/" + statusId + '.json';
		this._requestProxy(action, {}, 'POST', callback);
	},
	/* Users Infomation */
	/*
	 * フォロワーの取得
	 */
	getFollowers : function(data, callback){
		var url = "http://api.twitter.com/1/statuses/followers.json?callback=?";
		this._get(url, data, callback);
	},
	/*
	 * フォロワーのid一覧の取得
	 */
	getFollowersids : function(data, callback){
		var url = "http://api.twitter.com/1/followers/ids.json?callback=?";
		this._get(url, data, callback);
	},
	/*
	 * フォローしている人の取得
	 */
	getFriends : function(data, callback){
		var url = "http://api.twitter.com/1/statuses/friends.json?callback=?";
		this._get(url, data, callback);
	},
	/*
	 * フォローしている人のid一覧の取得
	 */
	getFriendsids : function(data, callback){
		var url = "http://api.twitter.com/1/friends/ids.json?callback=?";
		this._get(url, data, callback);
	},

	showUser :  function(data, callback){
		var url = "http://api.twitter.com/1/users/show.json?callback=?";
		this._get(url, data, callback);
	},
	/* Lists */
	getAllLists : function(data, callback){
		var action = "http://api.twitter.com/1/lists/all.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	getStatusesOfLists: function(data, callback){
		var action = "http://api.twitter.com/1/lists/statuses.json";
		this._requestProxy(action, data, 'GET', callback);
	},
	createListMembers : function(data, callback){
		var action = "http://api.twitter.com/1/lists/members/create.json";
		this._requestProxy(action, data, 'POST', callback);
	},
	destroyListMembers : function(data, callback){
		var action = "http://api.twitter.com/1/lists/members/destroy.json";
		this._requestProxy(action, data, 'POST', callback);
	},	
	getListMembers : function(data, callback){
		var action = "http://api.twitter.com/1/lists/members.json";
		this._requestProxy(action, data, 'GET', callback);
	}
	
}
